import javax.mail.*;

import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

public class MailSender {
    public static void main(String[] args) {
        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.qq.com"); // SMTP服务器地址
        props.put("mail.smtp.port", "587"); // SMTP服务器端口号
        props.put("mail.smtp.auth", "true"); // 是否需要身份认证
        props.put("mail.smtp.starttls.enable", "true"); // 使用STARTTLS安全连接

        // 创建会话
        Session session = Session.getInstance(props,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
//                        fdbctxnfdzldbbeb
                        return new PasswordAuthentication("627245048@qq.com", "*****");
                    }
                });

        try {
            // 创建邮件消息
            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("627245048@qq.com")); // 发件人地址
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("yucheng.zhang2@gientech.com")); // 收件人地址
            message.setSubject("测试"); // 邮件主题
            message.setText("测试"); // 邮件内容

            // 发送邮件
            Transport.send(message);

            System.out.println("邮件发送成功");

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
    }


